#ifndef MAIN_H
#define MAIN_H
#include <Arduino.h>
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <WiFiClient.h>
#include <ESP8266HTTPClient.h>
#include <TFT_eSPI.h> 
#include <TJpg_Decoder.h>
#include <ArduinoJson.h>
#include "qr.h"
#include <Ticker.h>
// #include <renderSprite.h>

#define VERSION "0.1.0"
#define AUTHOR "Zeeland"

Ticker ticker1;
int timeStamp = 0;    // ms
int custom_timeStamp = 0;

ESP8266WiFiMulti wifiMulti;
WiFiClient client;
HTTPClient http;
#define server_url "http://101.33.214.83:8086"
#define api_hello "/hello"
#define api_get_listing "/spire/getListing"
#define api_get_config "/currentConfig/get"
#define URL(a,b) a b

TFT_eSPI tft = TFT_eSPI();  // 引脚请自行配置tft_espi库中的 User_Setup.h文件
TFT_eSprite clk = TFT_eSprite(&tft);
#define LCD_BL_PIN 5               //LCD背光引脚
int LCD_BL_PWM = 50;               //屏幕亮度0-100，默认50
uint16_t bgColor = 0x0000;

byte loadNum = 6;                  // 加载时间

// 存放每日清单
typedef struct{
  String *listing;
  int size;
}listing_info;

// 模式选择
enum{
  MODE_HOME,
  MODE_LISTING,
  MODE_BANNER,
  MODE_NUM
}MODE;

#include "font/ZdyLwFont_20.h"
#include "img/pangzi/i0.h"
#include "img/pangzi/i1.h"
#include "img/pangzi/i2.h"
#include "img/pangzi/i3.h"
#include "img/pangzi/i4.h"
#include "img/pangzi/i5.h"
#include "img/pangzi/i6.h"
#include "img/pangzi/i7.h"
#include "img/pangzi/i8.h"
#include "img/pangzi/i9.h"

int Anim = 0;           //太空人图标显示指针记录
int AprevTime = 0;      //太空人更新时间记录

void clockTick();
void wifiInit();
void tftInit();
bool tft_output(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t* bitmap);
void SmartConfig();
void imgAnim();
void clientInit();
String httpGet(String url);

void renderSpriteLoading(byte delayTime);
void renderSpritePageInit();
void renderSpriteBlank();
void renderSpriteWifiConnFailed();
void renderSpriteWifiConnSuccess();
void renderSpriteServerConnFailed();
void renderSpriteServerSuccess(String input);
void renderSpritePageHome();
void renderSpritePageHomeError();
void renderSpritePageListing(listing_info *listing);
void renderSpritePageBanner();
void renderSpriteRefresh();

listing_info *homeParser(String content);

#endif